<?php

namespace app\common\model;

use app\common\model\account\ShopAccountModel;
use think\facade\Db;


class ProduceTypeModel extends CommonModel{

    protected  $name = 'beautiful_produce_type';

    protected  $pk   = 'id';

    public static function info($where){
        $info = Db::name('beautiful_produce_type')->alias('a')
            ->where(['a.is_delete'=>0])
            ->when(!empty($where['shop_id']),function ($query) use ($where){
                $query->where(['a.shop_id'=>$where['shop_id']]);
            })
            ->when(!empty($where['id']),function ($query) use ($where){
                $query->where(['a.id'=>$where['id']]);
            })
            ->when(isset($where['is_effect']),function ($query) use ($where){
                $query->where(['a.is_effect'=>$where['is_effect']]);
            })
            ->field("a.*")
            ->find();
        return $info;
    }
    public static function list($where,$order,$page=1,$limit=10){
        $query = Db::name('beautiful_produce_type')->alias('a')
            ->where(['a.is_delete'=>0])
            ->when(!empty($where['shop_id']),function ($query) use ($where){
                $query->where(['a.shop_id'=>$where['shop_id']]);
            })
            ->when(!empty($where['origin_type']),function ($query) use ($where){
                $query->where(['a.origin_type'=>$where['origin_type']]);
            })
            ->when(!empty($where['id']),function ($query) use ($where){
                $query->where(['a.id'=>$where['id']]);
            })
            ->when(isset($where['is_effect']),function ($query) use ($where){
                $query->where(['a.is_effect'=>$where['is_effect']]);
            })
            ->field("a.*");
        $count=$query->count();
        $list=$query->order($order)
            ->limit($limit)->page($page)
            ->select()
            ->toArray();
        return compact('count','list');
    }
    public static function up($data,$where){
        $data['edit_time']=date('Y-m-d H:i:s');
        $res=self::update($data,$where);
        return $res;
    }
}

